#pragma once

#include "common.h"
#include "Console.h"

class File
{
public:

	enum FileMode
	{
		FILE_READ = 1,
		FILE_WRITE = 2,
	};

	enum FileCursorMove
	{		
		FILE_CUR_BEGIN = 1,
		FILE_CUR_CURRENT,
		FILE_CUR_END
	};

	File(void);
	File(const char* filename, FileMode mode);
	File(std::string filename, FileMode mode);
	~File(void);

	bool Open(const char* filename, FileMode mode);
	bool Open(std::string filename, FileMode mode);

	void Close();
	u32 GetSize() const;
	HANDLE GetHandle() const;

	u32 Read(u8* buffer, u32 bytes);
	u32 Write(const u8* buffer, u32 bytes);

	void MoveCursor(u32 value, FileCursorMove cursor);

	bool IsOpened() const;

	//helper functions
	u32 Read8b(u8* buffer);
	u32 Read16b(u8* buffer);
	u32 Read32b(u8* buffer);
	u32 Read64b(u8* buffer);

	u32 Write8b(const u8* buffer);
	u32 Write16b(const u8* buffer);
	u32 Write32b(const u8* buffer);
	u32 Write64b(const u8* buffer);

private:
	HANDLE hFile;
	DWORD dwDesiredAccess;
	DWORD dwShareMode;
	DWORD dwCreationDisposition;
	DWORD dwFlagsAndAttributes;

	void CreateFlags(FileMode mode);
	bool opened;
};

